<template>
  <div id="app" class="p-4">
    <h2>《长安十二时辰》-望楼传信系统（二进制版）</h2>
    <h4 class="charts">
      <span class="pt-4" style="width:2rem; display:inline-block" v-for="(v, i) in charts" :key="i">
        {{v}}{{i}}
      </span>
    </h4>
    <div class="pt-3 d-flex justify-content-center">
      <div class="box"
      v-for="(n, i) in lights" :key="i"
      :class="{active: n}"
      @click="$set(lights, i, 1-n)"
      >
        {{n}}
      </div>
    </div>
    <p class="pt-2">结果：<span>{{num}}：{{chart}}</span></p>
  </div>
</template>

<script>

export default {
  name: 'app',
  data() {
    return {
      charts: '张督尉 狼 入 东市 西市 平康 怀远 皇城 天下 原来 是 你 的 故事'.split(' '),
      lights: Array(4).fill(0)
    }
  },
  computed: {
    num() {
      return parseInt(this.lights.join(''), 2)
    },
    chart() {
      return this.charts[this.num]
    }
  }
}
</script>

<style>
body {
  background: #000;
  color: #ccc;
  font-family: 'SKTaiti';
  text-align: center;
}
.box {
  width: 4rem;
  height: 4rem;
  background: #222;
  margin: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 0.5rem;
}
.box.active {
  background: #ecc;
  color: blue;
}
</style>
